<template>
  <div class="purse_report">
    <div class="top_box">
      <dt-search ref="search" :xlBtn="4">
        <Button type="primary" @click="onExport" v-if="unlocking('0215020101')">导出</Button>
      </dt-search>
    </div>
    <div class="mid_box">
      <div>总金额：{{ totalAmount }}元</div>
      <div>已提金额：{{ withdrawAmount }}元</div>
      <div>未提金额：{{ unWithdrawAmount }}元</div>
    </div>

    <dt-grid ref="table" :page="page" :onFetch="onFetch"></dt-grid>
  </div>
</template>

<script>
  import SearchOpt from '../opt/search.js'
  import column from '../opt/dataColumn.js'
  import purseMgr from './biz/index.js'
  export default {
    data() {
      return {
        totalAmount: '0',
        withdrawAmount: '0',
        unWithdrawAmount: '0',
        page: {
          total: 0
        },
        parmas: {
          orgIds: [],
          housesId: null,
          housesName: null,
          userId: null
        },
        tabsVal: '4',
        needData: {}
      }
    },

    mounted() {
      this.$refs.search.init(this.$refs.table, new SearchOpt(), this.parmas)
      this.$refs.table.init(this, new column(this))
      this.$refs.table.fetch()
    },

    methods: {
      onFetch(info) {
        console.log(this.parmas)
        this.needData = {
          ...info,
          housesId: this.parmas.housesId,
          orgIds: this.parmas.orgIds,
          userId: Number(this.parmas.userId) || null
        }
        return purseMgr.getWalletWebList(this.needData).then((res) => {
          this.getMoneyData(this.needData)
          this.page.total = res.total
          return res.list
        })
      },
      getMoneyData(needData) {
        purseMgr.getWalletListStatistics(needData).then((res) => {
          if (res) {
            this.totalAmount = res.totalAmount
            this.withdrawAmount = res.withdrawAmount
            this.unWithdrawAmount = res.unWithdrawAmount
          } else {
            this.totalAmount = 0
            this.withdrawAmount = 0
            this.unWithdrawAmount = 0
          }
        })
      },
      onExport() {
        purseMgr.walletWebListExport(this.needData)
      }
    }
  }
</script>

<style lang="scss" scoped>
  .purse_report {
    padding: 24px;
  }
  .mid_box {
    display: flex;
    div {
      margin-right: 36px;
      font-size: 16px;
    }
  }
</style>
